package controller;

import controller.exception.RegistrationException;
import facade.PersonFacade;
import facade.UserFacade;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import model.User;

/**
 *
 * @author ZimmE
 */
@Stateless
@LocalBean
public class RegisterController {

    @EJB
    private UserFacade userFacade;
    @EJB
    private PersonFacade personFacade;

    public void register(User user) throws RegistrationException {
        try {
            personFacade.create(user.getPersonId());
            userFacade.create(user);
            Logger.getLogger("MyGrona").log(Level.INFO, "User created");
        } catch (EJBException ex) {
            Logger.getLogger("MyGrona.error").log(Level.SEVERE, null, ex);
            throw new RegistrationException("User creation failed");
        }
    }
}
